<%@ page import="BusinessLogic.ControllerFacade" %>
<%@ page import="Presentation.WebUI.LinksGenerator" %>
<%@ page errorPage="error.jsp" %>

<%
	ControllerFacade c = (ControllerFacade)session.getAttribute("c");
%>

<h2>Search users</h2>

<%
    String startWith = request.getParameter("startWith");
    String keyword = request.getParameter("keyword");
    String method = request.getParameter("method");
    String rankParam = request.getParameter("rank");
    if(method == null) method = "ALL";
    int rank = 1;
    if(rankParam != null) rank = Integer.parseInt(rankParam);

    int amount = c.getListLength();
    int start = 0;

    String startParam = request.getParameter("start");
    if (startParam != null)
        start = Integer.parseInt(startParam);

    String[] list = c.searchUser(keyword,method,start,startWith);

    if(method.equals("ALL") || keyword == null)
        out.println("<h3>Showing ALL users</h3>");
    else
        out.println("<h3>Showing users where "+method+" is "+keyword.toUpperCase()+"</h3>");

    out.println(LinksGenerator.letterNav("SearchUser",method,keyword));

    String[] show = new String[list.length];
    int i = 0;
    for(String m : list) {
        show[i] = LinksGenerator.userLink(m);
        i++;
    }

    String last = "<br />No More Users<br /><br />";
    out.println(LinksGenerator.showListWithNavButtons(show, request.getParameterMap(), start, amount, last));
%>
